package Filter.Filter01;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;

import java.io.IOException;
import java.io.PrintWriter;

@WebFilter(filterName = "MyFilter",urlPatterns = "/MyServlet")
//@WebFilter(filterName = "MyFilter",urlPatterns = "/*")  //拦截用户所有请求
public class MyFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        PrintWriter out = servletResponse.getWriter();
        out.write("Hello MyFilter");
    }

    @Override
    public void destroy() {

    }
}
